<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    [#include "/includes/header.html" /]
    <script type="text/javascript">
        var qname = "";
        $(document).ready(function () {
            searchItems();
            $("#myqueryBtn").click(function () {
                qname = $("#q_pond_txt").val();
                searchItems();
            });
        });

        var pageClick = function (pageNo) {
            searchItems(pageNo);
        }

        var searchItems = function (currPage) {
            var params = {};
            //其他查询条件
            if (currPage) {
                params.page = currPage;
            }

            if (qname != null && "" != qname) {
                params.qname = qname;
            }
            params.active = $("#a_status_sel").val();
            $("#mainTable").mask("加载中...");
            var url = obz.ctx + "/fans/list";
            obz.ajaxJson(url, params, function (resp) {
                var result = resp.data;
                $(".itemsLotGrid").empty();

                if (currPage) {
                    $("#pager").pager({
                        pagenumber: currPage,
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                } else {
                    $("#pager").pager({
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                }

                var dataList = result.list;
                if (dataList.length > 0) {
                    for (var i = 0; i < dataList.length; i++) {
                        var _row = dataList[i];
                        if (_row.active == 1) _row.active = "正常";
                        else _row.active = "禁用";
                        if (_row.sex == 1) _row.sex = "男";
                        else _row.sex = "女";
                        var trHtml = obz.dataTemplate4obj($("#item_table_tr_tpl").html(), _row);
                        $(".itemsLotGrid").append(trHtml);

                        if (_row.active == "禁用") {
                            $("#del_" + _row.id).hide();
                            $("#undel_" + _row.id).show();
                        } else {
                            $("#del_" + _row.id).show();
                            $("#undel_" + _row.id).hide();
                        }

                        if (_row.is_receiver == 1) {
                            $("#unreceiver_" + _row.id).show();
                            $("#receiver_" + _row.id).hide();
                        } else {
                            $("#unreceiver_" + _row.id).hide();
                            $("#receiver_" + _row.id).show();
                        }
                    }
                    //初始化checkbox点击事件
                    TBatch.checkCheckbox();
                    TBatch.initCheckboxClick();
                    TBatch.initOptEvent(TableOpt.init());

                    $("#mainTable tbody tr.package").each(function () {
                        var me = $(this);
                        if (me.find("span.fans_status").text() == '正常') {
                            me.find("a.unlahei_a").hide();
                        } else {
                            me.find("a.lahei_a").hide();
                        }
                    });
                } else {
                    $(".itemsLotGrid").append($("#table_noresult_tr_tpl").html());
                }

                $("#mainTable").unmask();
            });
        }

        var TableOpt = {
            //取消消息接收
            setUnReceiver: function (param) {
                obz.showMessage("确定取消消息接受者吗！", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/fans/setUnReceiver", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            obz.msg("已取消消息接收", function () {
                                searchItems();
                            });
                        } else {
                            obz.error(resp.msg);
                        }
                    });
                });
            },
            //设置为消息接收者
            setReceiver: function (param) {
                obz.showMessage("确定设置为消息接受者吗！", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/fans/setReceiver", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            obz.msg("设置成功", function () {
                                searchItems();
                            });
                        } else {
                            obz.error(resp.msg);
                        }
                    });
                });
            },
            del: function (param) {
                obz.showMessage("确定禁用吗？禁用后会员不可访问公众号！", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/fans/del", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            obz.msg("禁用成功", function () {
                                searchItems();
                            });
                        } else {
                            obz.error(resp.msg);
                        }
                    });
                });
                return false;
            },
            undel: function (param) {
                obz.showMessage("确定恢复吗？", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/fans/undel", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            obz.msg("恢复成功", function () {
                                searchItems();
                            });
                        } else {
                            obz.error(resp.msg);
                        }
                    });
                });
                return false;
            },
            init: function () {
                var optArray = new Array();
                optArray.push(this.setUnReceiver);
                optArray.push(this.setReceiver);
                optArray.push(this.del);
                optArray.push(this.undel);
                return optArray;
            }
        }
    </script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
[#include "/includes/menus.html" /]
<div class="wrapper wrapper-content">
    <div id="tableList" class="content row ibox-content">
        <table class="table-striped">
            <tr>
                <td colspan="3" style="text-align: left;">&nbsp;&nbsp;
                    <input type="text" name="q_pond_txt" id="q_pond_txt" class="input-text"
                           style="width:190px; color:#DFDFDF" value="输入会员"
                           onfocus="if(this.value=='输入会员'){this.value=''};this.style.color='black';"
                           onblur="if(this.value==''||this.value=='输入会员'){this.value='输入会员';this.style.color='#DFDFDF';}"/>
                    &nbsp;&nbsp;&nbsp;
                    <select id="a_status_sel" style="width: 102px">
                        <option value="-1">全部</option>
                        <option value="1" selected="selected">正常</option>
                        <option value="0">被禁用</option>
                    </select>
                    &nbsp;&nbsp;&nbsp;
                    <button id="myqueryBtn" class="btn btn-success btn-sm">查询</button>
                </td>
            </tr>
        </table>

        <div id="prizeToolsbar" class="panel-body">
            <div id="pager" class="jqpager" style="margin-bottom: 1px;"></div>
        </div>
        <table id="mainTable" class="table table-striped table-bordered bootstrap-datatable datatable" border="0">
            <thead>
            <tr>
                <th>
                    <input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/>
                </th>
                <th>
                    <span style="vertical-align: middle;">&nbsp;&nbsp;昵称</span>
                </th>
                <th>性别</th>
                <th>地区</th>
                <th>首次来访时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody class="itemsLotGrid">
            </tbody>
        </table>
    </div>
</div>

<!-- html 模板文件 -->
<script type="text/template" id="item_table_tr_tpl">
    <tr class="package">
        <td>
            <input type="checkbox" class="commchk" id="checkbox_{id}"
                   style="margin-right: 4px; vertical-align: middle;"/>
            <input type="hidden" value="{id}"/>
        </td>
        <td>
				<span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">
					<img src="{headimgurl}" width="40" height="40">&nbsp;&nbsp;{nickname}</img>
				</span>
        </td>
        <td>
				<span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">
				{sex}
				</span>
        </td>
        <td>
				<span class="isArrive">
				{province}
				</span>
        </td>
        <td>{created}</td>
        <td>
            <span class="fans_status">{active}</span>
        </td>
        <td>
            &nbsp;<a id="unreceiver_{id}" href="javascript:void(0)">取消消息接受</a>
            &nbsp;<a id="receiver_{id}" href="javascript:void(0)">设为消息接收者</a>
            &nbsp;<a id="del_{id}" href="javascript:void(0)">禁用</a>
            &nbsp;<a id="undel_{id}" href="javascript:void(0)">恢复</a>
        </td>
    </tr>
</script>
<script type="text/template" id="table_noresult_tr_tpl">
    <tr class="package">
        <td colspan="7" class="center">
            没有结果集
        </td>
    </tr>
</script>
[#include "/includes/footer.html" /]
<script type="text/javascript">
    Template.init("#menu-fans");
</script>
</body>
</html>	